home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 867 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  953 b 

  1. Path: ukcc.uky.edu!JJSTEP00
  2. From: JJSTEP00@ukcc.uky.edu (Jason Stephenson)
  3. Newsgroups: comp.lang.c
  4. Subject: pseudo-random numbers
  5. Date: Tue, 09 Jan 96 15:05:04 EST
  6. Organization: The University of Kentucky
  7. Message-ID: <17709D420S86.JJSTEP00@ukcc.uky.edu>
  8. NNTP-Posting-Host: ukcc.uky.edu
  9.  
  10. I know what the c.l.c. FAQ says about pseudo-random numbers, so I wonder why
  11. I seem to get "better" results with "rand() % n + 1" than I get when I use
  12. "n * rand() / RAND_MAX + 1"  Am I missing some parenthesis or something?
  13. Oh yeah, and I usually call "srand(clock())" once in the initialization of
  14. my program.  With the first, I get an integer between 1 and n.  With the
  15. second, I almost always get a value of 1 or 2.
  16.  
  17. +----------------------------+-----------------------------+
  18. |     Jason Stephenson       | "Curiouser and curiouser,"  |
  19. |   jjstep00@ukcc.uky.edu    |        said Alice.          |
  20. +----------------------------+-----------------------------+
  21.